package com.example.lovewordsapplication.utils;

import okhttp3.Callback;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 * OkHttp工具类
 *
 * @author Leung
 * @date 2020/4/7 23:37
 */
public class OkHttpUtil {

    private static OkHttpClient client;

    static { client = new OkHttpClient(); }

    /**
     * post异步请求
     * @param callback 回调接口
     */
    public static void request(Callback callback) {
        FormBody.Builder builder = new FormBody.Builder();
        builder.add("key", "68ca25962a557b92d8dc5832a7bbe5bd");
        RequestBody body = builder.build();
        Request request = new Request.Builder()
                .url("http://api.tianapi.com/txapi/saylove/index")
                .post(body)
                .build();
        client.newCall(request).enqueue(callback);
    }

}
